#!/usr/bin/python3

from datetime import datetime
from datetime import date
from datetime import timedelta




qingming = ['2024/04/04','2024/04/05','2024/04/06']
wuyi = ['2024/05/01','2024/05/02','2024/05/03','2024/05/04','2024/05/05']
duanwu = ['2024/06/08','2024/06/09','2024/06/10',]
zhongqiu = ['2024/09/15','2024/09/16','2024/09/17',]
guoqing = ['2024/10/01','2024/10/02','2024/10/03','2024/10/04','2024/10/05','2024/10/06','2024/10/07']


six = ['2024/05/11','2024/09/14','2024/10/12']
seven = ['2024/04/07','2024/04/28','2024/09/29']

# 统计工作日
def total_workday(start_date,end_date):
    if type(start_date) != date or type(end_date) != date:
        return -1
    sum = 0
    duration = end_date-start_date
    for i in range(duration.days+1):
        temp_date = start_date+timedelta(days=i)
        temp_date_str = temp_date.strftime('%Y/%m/%d')
        if temp_date.isoweekday() == 6 and temp_date_str not in six:
            continue
        elif temp_date.isoweekday() == 7 and temp_date_str not in seven:
            continue
        elif temp_date_str in qingming or temp_date_str in wuyi or temp_date_str in duanwu or temp_date_str in zhongqiu or temp_date_str in guoqing:
            continue 
        else:
            sum+=1
    # print(start_date,end_date,duration.days,sum)
    return sum

    
     
    
    


def init():
    delay_days = 14
    # 5
    old_start = date(2024,3,21)
    old_end = date(2024,3,21)


    new_start = old_start + timedelta(days=delay_days-1)

    temp_str_new_start = new_start.strftime('%Y/%m/%d')
    # 判断是否在节假日里面
    # 在，节假日最后一天+1；不在，直接赋值
    if temp_str_new_start in qingming:
        new_start = datetime.strptime(qingming[-1],"%Y/%m/%d").date()+timedelta(days=1)
    elif temp_str_new_start in wuyi:
        new_start =  datetime.strptime(wuyi[-1],"%Y/%m/%d").date()+timedelta(days=1)
    elif temp_str_new_start in duanwu:
        new_start =  datetime.strptime(duanwu[-1],"%Y/%m/%d").date()+timedelta(days=1)
    elif temp_str_new_start in zhongqiu:
        new_start =  datetime.strptime(zhongqiu[-1],"%Y/%m/%d").date()+timedelta(days=1)
    elif temp_str_new_start in guoqing:
        new_start =  datetime.strptime(guoqing[-1],"%Y/%m/%d").date()+timedelta(days=1)
    else:
        pass
   
    # 判断是否为休息日
    temp_str_new_start = new_start.strftime('%Y/%m/%d')
    if new_start.isoweekday() == 6 and temp_str_new_start not in six:
        new_start = new_start+timedelta(days=2)
    elif new_start.isoweekday() == 7 and temp_str_new_start not in seven:
        new_start = new_start+timedelta(days=1)
    else:
        pass

     

    # 统计工作日
    task_duration = total_workday(old_start,old_end)
    
    task_duration1= task_duration
    #  结束日期
    # 从开始日期累计+1，如果日期为休息日或者节假日 则跳过task_duration-1
    new_end = new_start + timedelta(days=-1)

    while task_duration >0:
        new_end = new_end + timedelta(days=1)
        
        temp_end_str = new_end.strftime('%Y/%m/%d')
        if new_end.isoweekday() == 6 and temp_end_str not in six:
            pass
        elif new_end.isoweekday() == 7 and temp_end_str not in seven:
            pass
        elif temp_end_str in qingming or temp_end_str in wuyi or temp_end_str in duanwu or temp_end_str in zhongqiu or temp_end_str in guoqing:
            pass
        else:
            # print("--",new_end,task_duration)
            task_duration=task_duration-1   
        
        
        


    print(new_start,new_end,task_duration1)






if __name__ == '__main__':
    init()


# ''